const reg = /<SubItem.+title="(.+)">(.|\r?\n)+?id="(\w+)?"/g

const singleReg = /<SubItem.+title="(.+)">(.|\r?\n)+?id="(\w+)?"/
const isCollectReg = /collect:( )?true/

// todo! 修复某些mdx正则无法匹配的问题（keroro、ekira等
export default function getItemsFromCollect(mdx: string, basePath: string) {
  const res = []
  if (!isCollectReg.test(mdx)) return []

  const arr = mdx.match(reg) || []
  for (const s of arr) {
    const item = singleReg.exec(s)!
    res.push({
      id: item[3],
      name: item[1],
      path: `${basePath}#${item[1]}`,
    })
  }

  return res
}